package ferp.core.ai.strategy.simple;

import ferp.core.ai.strategy.Misere;
import ferp.core.card.Card;
import ferp.core.player.AI;

/**
 * User: igorgok
 * Date: 5/30/11 2:12 PM
 */
public class SimpleMisere extends Misere
{
  @Override
  public Card move(AI ai)
  {
/*
    // determine if this player is a declarer
    if (Game.ferp().declarer == ai)
    {
      if (Game.ferp().hand == 0)
      {
        // this player is a declarer and the first hand
        // one of the suits *must* contain 8 - find it and play it
        for (Card.Suit s : Card.Suit.rising)
          if (ai.hand.cards(s).contains(Card.Rank.EIGHT))
            return Game.ferp().deck().card(s, Card.Rank.EIGHT);

        // should never get here
        assert false: "player has no 8??";
      }
      else
      {
        // this player is a declarer but *not* the first hand
        Card highest = Game.ferp().trick.highest(Game.ferp().trump());
        Card.Set set = ai.hand.cards(highest.suit());

        if (set.size() == 0)
        {
          // play any of the highest cards we have
          for (Card.Suit suit : Card.Suit.rising)
          {
             set = ai.hand.cards(suit);

             if (set.size() > 0)
               return Game.ferp().deck().card(suit, set.highest());
          }

          // should never get here
          assert false: "player has no cards??";
        }
        else
          // play the highest card of the suit that lower than trick's highest card
          return Game.ferp().deck().card(highest.suit(), set.lower(highest.rank()));
      }
    }
    else
    {
      // this player is *not* a declarer
      Hand candidates = Game.ferp().current.player.hand.getMoveCandidates();
      Card dc = Game.ferp().trick.get(Game.ferp().declarer);

      for (Card.Suit s : Card.Suit.rising) {
        if (candidates.cards(s).size() > 0) {
          // if declarer still have to move - put the lowest card
          if (dc == null)
            return Game.ferp().deck().card(s, candidates.cards(s).lowest());

          // try to put a lower card than declarer put - maybe he will take the trick
          Card.Rank lower = candidates.cards(s).lower(dc.rank());
          if (dc.suit() == s && lower != null)
            return Game.ferp().deck().card(s, lower);

          return Game.ferp().deck().card(s, candidates.cards(s).highest());
        }
      }

      assert false : "player has no cards??";
    }
*/

    return null;
  }
}
